﻿using Microsoft.Xna.Framework;
using DrawableObjects.Actors.Projectiles;

namespace DrawableObjects.Actors.Weapons
{
    public class Weapon
    {
        public enum WeaponType { Plasma, Missile, Laser, Sonarwave, Lightning, Heal };


        private float cooldown
        {
            get;
            set;
        }

        private float nextReadyTime
        {
            get;
            set;
        }

        private Projectile projectile
        {
            get;
            set;
        }

        /// <summary>
        /// checks if the weapon can fire again
        /// </summary>
        public virtual bool isReady()
        {
            if (nextReadyTime <= 0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// updates the ready time of the weapon
        /// </summary>
        public void Update()
        {
            if (nextReadyTime > 0)
            {
                nextReadyTime -= (float)GlobalGameClasses.GlobalGameValues.Values.gameTime.ElapsedGameTime.TotalMilliseconds;
            }
        }

        /// <summary>
        /// fires, when the weapon is ready.
        /// creates a projectile
        /// </summary>
        public Projectile fire(Vector2 direction, Vector2 launchPoint)
        {
            if (nextReadyTime <= 0)
            {
                nextReadyTime = cooldown;
                return projectile.Clone(launchPoint, direction);
            }
            else
            {
                return null;
            }
        }

        public Weapon(Projectile projectile, float reloadTime)
        {
            this.projectile = projectile;
            this.cooldown = reloadTime;
            this.nextReadyTime = 0;
        }

    }
}

